package com.zhny.aiot.soil.plugin;

import com.zhny.aiot.plugin.ICenterFacilities;
import com.zhny.aiot.plugin.IDevice;
import com.zhny.aiot.plugin.modbus.ModemServer;
import com.zhny.aiot.plugin.modbus.device.ModemConfig;
import com.zhny.aiot.plugin.modbus.device.ModemDeviceFactory;
import com.zhny.aiot.plugin.modbus.handler.model.ModemRequestMessage;
import com.zhny.aiot.plugin.model.DeviceEntity;
import com.zhny.aiot.plugin.model.FactoryType;
import com.zhny.aiot.plugin.model.StoreEntity;
import com.zhny.aiot.soil.plugin.model.SoilStoreEntry;
import org.pf4j.Extension;
import org.pf4j.Plugin;
import org.pf4j.PluginWrapper;

public class SoilPlugin extends Plugin {
    public SoilPlugin(PluginWrapper wrapper) {
        super (wrapper);
    }
    @Extension
    public static class SoilFactory extends ModemDeviceFactory<SoilStoreEntry> {

        public ModemRequestMessage getRequestMessage(ModemConfig modemConfig) {
            return new ModemRequestMessage (Integer.parseInt (modemConfig.getAddress ()),(short) 3,0,4);
        }

        public IDevice createDevice(ICenterFacilities iCenterFacilities, DeviceEntity entity) {
            return new SoilDevice (ModemServer.getInstance ().getEngine () ,this,iCenterFacilities,entity);
        }

        public Class<? extends StoreEntity> storeClass() {
            return SoilStoreEntry.class;
        }

        public String getId() {
            return "jdrk-soil-3&1-plugin";
        }

        public String getName() {
            return "建大仁科电导率土壤插件";
        }

        public FactoryType getType() {
            return FactoryType.SoilMoisture;
        }
    }
}
